import Vue from 'vue'
import Vuex from 'vuex'
import products from './module/products'
import cart from './module/cart'
Vue.use(Vuex)

const myPlugin = store => {
  store.subscribe((mutation,state)=>{
    if(mutation.type.startsWith('cart/')){
      window.localStorage.setItem('cart-products',JSON.stringify(state.cart.cartProducts))
    }
  })
}
export default new Vuex.Store({
  state: {
  },
  mutations: {
  },
  actions: {
  },
  modules: {
    products,
    cart
  },
  plugins:[myPlugin]
})
